#include <iostream>
#include <climits>

using namespace std;

const int N=2e5+10;

int n;
int a[N],dp[N]; 

int main() 
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	
	int ret=INT_MIN;
	for(int i=n;i>=1;i--)
	{
		dp[i]=max(a[i],a[i]+dp[i+1]);
		ret=max(ret,dp[i]);
	}
	
	cout<<ret<<endl;
	
	return 0;
}
